package com.team7.happycommunity.parkservice.controller;

import com.team7.happycommunity.parkservice.common.CommonResult;
import com.team7.happycommunity.parkservice.dao.ParkingRentRecordsMapper;
import com.team7.happycommunity.parkservice.dto.MyParkingRecordsDTO;
import com.team7.happycommunity.parkservice.dto.ParkingRentDTO;
import com.team7.happycommunity.parkservice.dto.ParkingRentDateDTO;
import com.team7.happycommunity.parkservice.service.ParkingRentRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/parkingrent")
public class ParkingRentRecordsController {


    @Autowired
    ParkingRentRecordsService parkingRentRecordsService;

    // 获取当前车位所有出租信息
    @GetMapping("/rlist")
    @ResponseBody
    public CommonResult getRecerdsList(Integer id){
        List<ParkingRentDateDTO> list = parkingRentRecordsService.getRecords(id);
        return CommonResult.success(list);
    }

    // 获取自己的租用车位信息
    @GetMapping("/mylist")
    @ResponseBody
    public CommonResult getMyRecordsList(String username){
        List<MyParkingRecordsDTO> list = parkingRentRecordsService.getMyRecords(username);
        return CommonResult.success(list);
    }


    @PostMapping("/add")
    @ResponseBody
    public CommonResult add(@RequestBody ParkingRentDTO parkingRentDTO){
        int i = parkingRentRecordsService.add(parkingRentDTO);
        return i == 0?CommonResult.failed():CommonResult.success();
    }

}
